<?php
/*
 *   This file is part of verbum.
 *
 *   poat is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   poat is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with poat.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * 	 Copyright (c) 2008 Sergio Gabriel Teves <gabriel.sgt at gmail.com>
 */
 
class String {
 
	public static function format($string,$array,$keyed=false) {
		if (is_array($array)) {
			if ($keyed) {
				foreach ($array as $key => $value) {
					$string = str_replace("{".$key."}", $value, $string);
				}
			} else {
				for ($i = 0; $i < count($array); $i++) {
					$string = str_replace("{".$i."}", $array[$i], $string);
				}
			}
		} else {
			$string = str_replace("{0}", $array, $string);
		}
		return $string;
	}

	public static function startWith($string,$value) {
		$r = false;
		if (!(strlen($value)>strlen($string))) {
			if (substr($string,0,strlen($value))==$value) {
				$r = true;
			} 
		} 
		return $r;
	}
	
	public static function toString($mixed) {
		return "".$mixed."";
	}
	
	public static function isEmpty($var) {
		return ($var==null || $var=="");
	}
	
	function coallesce($var1,$var2) {
		if (String::isEmpty($var1)) {
			return $var2;
		}
		return $var1;
	}
	
}
?>
